package com.treeHole.treeHoleServer.controller;


import com.treeHole.treeHoleServer.pojo.RequestDataDTO.PostDeleteCommentDTO;
import com.treeHole.treeHoleServer.pojo.RequestDataDTO.UPCIdDTO;
import com.treeHole.treeHoleServer.pojo.Result;
import com.treeHole.treeHoleServer.pojo.ResultDataDTO.ResultCommentDTO;
import com.treeHole.treeHoleServer.service.CommentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
public class CommentController {

    @Autowired
    private CommentService commentService;

    @PostMapping("/likeCmt")
    public Result likeCmt(@RequestBody UPCIdDTO  upcIdDTO) {
        int resultCode=commentService.userLikeComment(upcIdDTO.getUserId(),upcIdDTO.getCmtId());
        log.info("收到用户点赞评论请求 upcIdDTO:{},处理结果:{}",upcIdDTO,resultCode);
        return resultCode==1?Result.success():Result.error("点赞评论失败!");
    }

    @PostMapping("/unlikeCmt")
    public Result unlikeCmt(@RequestBody UPCIdDTO  upcIdDTO) {
        int resultCode=commentService.userUnlikeComment(upcIdDTO.getUserId(),upcIdDTO.getCmtId());
        log.info("收到用户取消点赞评论请求 upcIdDTO:{},处理结果:{}",upcIdDTO,resultCode);
        return resultCode==1?Result.success():Result.error("取消点赞评论失败!");
    }

    @PostMapping("/createCmt")
    public Result createCmt(@RequestBody PostDeleteCommentDTO postDeleteCommentDTO) {
        log.info("收到用户创建评论请求,接收到的信息:{},开始处理!",postDeleteCommentDTO);
        ResultCommentDTO result=commentService.userCreateComment(postDeleteCommentDTO);
        log.info("收到用户创建评论请求,处理结果:{}",result);
        return Result.success(result);
    }

    @PostMapping("/deleteCmt")
    public Result deleteCmt(@RequestBody PostDeleteCommentDTO postDeleteCommentDTO) {
        int resultCode=commentService.userDeleteComment(postDeleteCommentDTO);
        log.info("收到用户删除评论请求,commentId:{}",postDeleteCommentDTO.getCmtId());
        return resultCode==1?Result.success():Result.error("删除评论失败!");
    }

}
